package SingleDemo;


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StartMovie {
    List<Movie> list = new ArrayList<>();
    private static Scanner sc=new Scanner(System.in);
    public void start(){
        while(true){
            ConsoleUtils.clearConsole();
            System.out.println("1.添加电影");
            System.out.println("2.删除电影");
            System.out.println("3.修改电影");
            System.out.println("4.查询电影");
            System.out.println("5.退出");
            System.out.println("请选择功能：");
            int choice=sc.nextInt();
            switch (choice){
                case 1:
                    addMovie();
                    break;
                case 2:

                    deleteMovie();
                    break;
                case 3:

                    modifyMovie();
                    break;
                case 4:

                    queryMovie();
                    break;
                case 5:
                    System.out.println("欢迎下次光临");
                    System.exit(0);
                    break;
                default:
                    System.out.println("输入错误，请重新输入");
                    break;
            }
            // 清屏逻辑（可根据需要实现）
            ConsoleUtils.clearConsole();
    }
}

    private Movie queryMovie( ) {
        System.out.println("请输入电影名称");
        String name=sc.next();
        for(Movie movie:list){
            if(movie.getName().equals(name)){
                System.out.println(movie);
                return movie;
            }
        }
        return null;
    }

    private void modifyMovie( ) {
        System.out.println("请输入电影名称");
        String name=sc.next();
        for(Movie movie:list){
            if(movie.getName().equals(name)){
                System.out.println("找到了");
                }
    }
        System.out.println("没有找到");
    }

    private void deleteMovie( ) {
        System.out.println("请输入电影名称");
        String name=sc.next();
        for(int i=0;i<list.size();i++) {
            if(list.get(i).equals(name)){
                list.remove(i);
                i--;
                System.out.println("删除成功");
                return;
            }
            }
    }

    private void addMovie() {
            Movie movie=new Movie();
            System.out.println("请输入电影名称");
            movie.setName(sc.next());
            System.out.println("请输入电影类型");
            movie.setType(sc.next());
            System.out.println("请输入电影评分");
            movie.setScore(sc.nextDouble());
            System.out.println("请输入主演");
            movie.setActor(sc.next());
            list.add(movie);
            System.out.println("添加成功");
    }
}
